# -*- coding: utf-8 -*-
"""
@Time ： 2022/12/31 20:59
@Auth ： jiraWu
@File ：jsonpath解析淘票票.py
@IDE ：PyCharm
@Motto:人生苦短，我学Python

"""
import json
from jsonpath import jsonpath
from jira_wu_dev_utils._request import GetRequest

url = "https://dianying.taobao.com/showAction.json?_ksTS=1672491649758_64&jsoncallback=jsonp65&action=showAction&n_s=new&event_submit_doGetSoon=true"
headers = {
    'accept': 'text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01',
    'accept-language': 'zh-CN,zh;q=0.9',
    'cookie': 'cna=7H4jG8PnHwwCAXjtjmTerLpU; t=010733090688c114cb9440e8d79985e1; cookie2=13dee67fca0a63fb10dc0693592901b3; v=0; _tb_token_=e1ee8a4e3be35; xlly_s=1; l=fBNa2DpeL2UZOBXFKOfaFurza77OSIRYYuPzaNbMi9fPOwfB5czcW67AwUY6C3GVFsEwR3rp2umHBeYBq3xonxvTaxom40kmndLHR35..; tfstk=czpABttac400KS0GUthuQlpz29mlwprOSkQTBp_pvywf9a1mtpvpT7ldbw7x2; isg=BJqaMJhKrSX0xSCYdlhn_1Zw60C8yx6lgcfGRaQTRi34FzpRjFtutWBh5-OLx5Y9',
    'referer': 'https://dianying.taobao.com/',
    'sec-ch-ua': '"Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"',
    'sec-ch-ua-mobile': '?0',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'same-origin',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36',
    'x-requested-with': 'XMLHttpRequest',
}

cont = GetRequest(url=url, headers=headers).send_req()
cont = cont.split("(")[1].split(")")[0]
with open('淘票票.json', 'w', encoding='utf-8') as f:
    f.write(cont)
obj = json.load(open('淘票票.json', 'r', encoding='utf-8'))
city_lis = jsonpath(obj, '$..country')
print(city_lis)
